TOPサイトポリシー掲示板について

キャスフィ避難所


TOP > 殺伐板 > 検索画面


スレタイ検索 本文検索 投稿者検索

12名無しさん
2019-07-19 23:25:21
ID:2od.PUZY

class Account:
def __init__(self):
# 2. to refer to the inner class, you must use self.Bank
# 3. no need to use an inner class here
self.bank = self.Bank()

class Bank:
def __init__(self):
self.balance = 100000

# 4. in your original code, you had a method with the same name as
# the attribute you set in the constructor. That meant that the
# method was replaced with a value every time the constructor was
# called. No need for a method to do a simple attribute lookup. This
# is Python, not Java.

def withdraw(self, amount):
self.balance -= amount

def deposit(self, amount):
self.balance += amount

a = Account()
print(a.bank.balance)

前ページ
次ページ